package com.bvr;


import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class EarningObjectAdapter extends ArrayAdapter<EarningObject> {

	private ArrayList<EarningObject> items;

	public EarningObjectAdapter(Context context, int textViewResourceId,
			ArrayList<EarningObject> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);

			v = vi.inflate(R.layout.earning_row, null);
		}
		EarningObject o = items.get(position);
		if (o != null) {

			TextView lblTitle = (TextView) v.findViewById(R.id.earningPropertyTitle);
			TextView lblLocation = (TextView) v.findViewById(R.id.earningPropertyLocation);
			TextView lblFrom = (TextView) v.findViewById(R.id.earningTransType);
			TextView lblDate = (TextView) v.findViewById(R.id.earningTransDate);
			TextView lblStatus = (TextView) v.findViewById(R.id.earningStatus);
			TextView lblRate = (TextView) v.findViewById(R.id.earningOwnerAmount);
			
			if (lblTitle != null) {
				lblTitle.setText(o.getPropertyTitle());				
			}
			if (lblLocation != null) {
				lblLocation.setText(o.getPropertyLocation());				
			}
			if (lblFrom != null) {
				lblFrom.setText(o.getTransType());				
			}
			if (lblDate != null) {
				lblDate.setText(o.getTransDate());				
			}
			if (lblStatus != null) {
				lblStatus.setText(o.getStatus());	
				if(o.getStatus().toString().equalsIgnoreCase("pending"))
				{					
					lblStatus.setTextColor(Color.RED);	
				}
				else
				{
					lblStatus.setTextColor(Color.parseColor("#43A51B"));
				}
			}
			if (lblRate != null) {
				lblRate.setText("$"+o.getOwnerAmount());				
			}		
		}
		return v;
	}
}
